package com.ag.dgm.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbAdviceWay;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;
import com.ag.dgm.service.IAdviceWayService;

@Controller("AdviceWayAction")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class AdviceWayAction extends BaseAction {

	@Resource(name="adviceWayServiceImpl")
	private IAdviceWayService service;

	private List<TbAdviceWay> adviceWays;

	private String result;

	private TbAdviceWay tbAdviceWay;

	public IAdviceWayService getService() {
		return service;
	}

	public void setService(IAdviceWayService service) {
		this.service = service;
	}

	public List<TbAdviceWay> getAdviceWays() {
		return adviceWays;
	}

	public void setAdviceWays(List<TbAdviceWay> adviceWays) {
		this.adviceWays = adviceWays;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public TbAdviceWay getTbAdviceWay() {
		return tbAdviceWay;
	}

	public void setTbAdviceWay(TbAdviceWay tbAdviceWay) {
		this.tbAdviceWay = tbAdviceWay;
	}

	public String find() {
		adviceWays = service.findAll();
		return "main";
	}

	public String modify() {
		this.setResult("修改成功");
		try {
			service.modify(tbAdviceWay);
		} catch (Exception e) {
			this.setResult("修改不成功");
		}
		return "modify_succ";
	}

	public String delete() {
		this.setResult("删除成功");

		try {
			service.delete(tbAdviceWay);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "delete_succ";
	}

	public String add() {
		tbAdviceWay.setA(IDUtil.PRESERVE);
		this.setResult("增加成功");
		
		try {
			service.add(tbAdviceWay);
		} catch (Exception e) {
			this.setResult("增加不成功");
		}
		return "add_succ";
	}

}
